// (C) 2022 Intel Corporation. All rights reserved.
// Your use of Intel Corporation's design tools, logic functions and other 
// software and tools, and its AMPP partner logic functions, and any output 
// files from any of the foregoing (including device programming or simulation 
// files), and any associated documentation or information are expressly subject 
// to the terms and conditions of the Intel Program License Subscription 
// Agreement, Intel FPGA IP License Agreement, or other applicable 
// license agreement, including, without limitation, that your use is for the 
// sole purpose of programming logic devices manufactured by Intel and sold by 
// Intel or its authorized distributors.  Please refer to the applicable 
// agreement for further details.

localparam AES_READCONFIG            = 5'b00001;
localparam AES_WRITECONFIG           = 5'b00010;
localparam AES_READDATA              = 5'b00100;
localparam AES_READDATA_M1           = 5'b01001;
localparam AES_WRITEDATA             = 5'b01101;

localparam AES_KEYEXPAND128          = 5'b01000;
localparam AES_KEYEXPAND192          = 5'b01011;
localparam AES_KEYEXPAND256          = 5'b01100;

localparam AES_ENCRYPT128            = 5'b11000;
localparam AES_DECRYPT128            = 5'b11001;
localparam AES_ENCRYPT192            = 5'b11010;
localparam AES_DECRYPT192            = 5'b11011;
localparam AES_ENCRYPT256            = 5'b11100;
localparam AES_DECRYPT256            = 5'b11101;

localparam AES_EXECUTE               = 5'b00011;
localparam AES_READKEYSTORE          = 5'b10010;
localparam AES_WRITEKEYSTORE         = 5'b10011;
localparam AES_COPYKEYSTORETOBUFFER  = 5'b10000;
localparam AES_COPYBUFFERTOKEYSTORE  = 5'b10001;

localparam AES_WRITEIV               = 5'b00101;
localparam AES_COPYIVSTORETOBUFFER   = 5'b00110;
localparam AES_COPYBUFFERTOIVSTORE   = 5'b00111;
localparam AES_READIV                = 5'b01010;

// number of rounds
localparam NR_128 = 4'ha;         // 128-bit key - 10 rounds
localparam NR_192 = 4'hc;         // 192-bit key - 12 rounds
localparam NR_256 = 4'he;         // 256-bit key - 14 rounds

// key size encodings
localparam NK_128 = 2'b00;        // 128-bit key
localparam NK_192 = 2'b01;        // 192-bit key
localparam NK_256 = 2'b10;        // 256-bit key

// key word select encodings
localparam ABCD = 2'b00;            // bits 255:128 of the working key
localparam CDEF = 2'b01;            // bits 191:64  of the working key
localparam EFGH = 2'b10;            // bits 127:0   of the working key
localparam GHCD = 2'b11;            // bits {63:0,191,128} of the working key

// cryption encodings
localparam ENCRYPT_OP = 1'b1;
localparam DECRYPT_OP = 1'b0;

localparam AFFINE_MATRIX_ROW0 = 8'b1_1_1_1_0_0_0_1;
localparam AFFINE_MATRIX_ROW1 = 8'b1_1_1_0_0_0_1_1;
localparam AFFINE_MATRIX_ROW2 = 8'b1_1_0_0_0_1_1_1;
localparam AFFINE_MATRIX_ROW3 = 8'b1_0_0_0_1_1_1_1;
localparam AFFINE_MATRIX_ROW4 = 8'b0_0_0_1_1_1_1_1;
localparam AFFINE_MATRIX_ROW5 = 8'b0_0_1_1_1_1_1_0;
localparam AFFINE_MATRIX_ROW6 = 8'b0_1_1_1_1_1_0_0;
localparam AFFINE_MATRIX_ROW7 = 8'b1_1_1_1_1_0_0_0;

localparam INVERSE_AFFINE_MATRIX_ROW0 = 8'b1_0_1_0_0_1_0_0;
localparam INVERSE_AFFINE_MATRIX_ROW1 = 8'b0_1_0_0_1_0_0_1;
localparam INVERSE_AFFINE_MATRIX_ROW2 = 8'b1_0_0_1_0_0_1_0;
localparam INVERSE_AFFINE_MATRIX_ROW3 = 8'b0_0_1_0_0_1_0_1;
localparam INVERSE_AFFINE_MATRIX_ROW4 = 8'b0_1_0_0_1_0_1_0;
localparam INVERSE_AFFINE_MATRIX_ROW5 = 8'b1_0_0_1_0_1_0_0;
localparam INVERSE_AFFINE_MATRIX_ROW6 = 8'b0_0_1_0_1_0_0_1;
localparam INVERSE_AFFINE_MATRIX_ROW7 = 8'b0_1_0_1_0_0_1_0;

// This is the "offset" vector for the affine and inverse affine transforms
// defined by the AES standard.  See the affine transform written in matrix notation
// above.
localparam AFFINE_C_VECTOR = 8'h63;

// This represents the polynomial m(x) = x**8 + x**4 + x**3 + x + 1 which is used
// in the GF(256) multiplication defined by the AES standard.  GF(256) multiplication
// is used in the mix_column and inverse_mix_column functions.
localparam AES_GF256_POLY = 8'h1b;
